package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.OperationLogMapper;
import com.woniuxy.entity.OperationLog;
import com.woniuxy.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

//服务层注解
@Service
public class OperationLogServiceImpl implements OperationLogService {
    @Autowired
    private OperationLogMapper operationLogMapper;


    /**
     * 分页查询
     *
     * @param condition
     * @param pageNum   当前页
     * @param pageSize  每页大小
     * @return 分页对象
     */
    @Override
    public PageInfo<OperationLog> findPage(Map<String, Object> condition, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OperationLog> list = operationLogMapper.findByCondition(condition);
        return new PageInfo<>(list);
    }

    //分页查询
//    @Override
//    public PageBean<OperationLog> findPage(int page, int size) {
//        int begin = (page - 1) * size;
//        List<OperationLog> data = operationLogMapper.findPage(begin, size);
//        int count = operationLogMapper.count();
//        return new PageBean<>(data,count,size);
//    }
    //添加日志
    @Override
    public int addOperationLog(OperationLog operationLog) {
        return operationLogMapper.save(operationLog);
    }
    //查询方法名日志
    @Override
    public OperationLog findByName(String methodName) {
        return operationLogMapper.findByName(methodName);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @Override
    public int deleteBatch(String[] ids) {
        return operationLogMapper.deleteBatch(ids);
    }

    /**
     * 多条件查询
     * * @param condition
     * * @param page
     * * @param size
     *
     * @param condition
     * @param page
     * @param size
     */
//    @Override
//    public PageBean<OperationLog> findByCondition(Map<String, Object> condition, int page, int size) {
//        //通过页码计算起始行
//        int begin = (page - 1) * size;
//        //调用DAO查询数据，封装成PageBean对象
//        List<OperationLog> data = operationLogMapper.findByCondition(condition, begin, size);
//        int count = (int) operationLogMapper.countByCondition(condition);
//        return new PageBean<>(data,count,size);
//    }
}
